package com.timoon.webcomponent.utility.pic.gridsmallpic;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.GridView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.request.resource.PackageResourceReference;

/**
 *<p>宫格图片</p>
 *<p>300px,3*3</p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class GridSmallPicPanel extends Panel {

	private List<String> picPath;
	
	private String title;
	
	/**
	 *
	 * @param id
	 * @param title 标题
	 * @param picPath 图片路径，9个
	 */
	public GridSmallPicPanel(String id,String title, List<String> picPath) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.picPath=picPath;
		
		this.title=title;
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		renderTitle();
		
		renderGrid();
	}

	private void renderTitle() {
		// TODO Auto-generated method stub
		add(new Label("wk_title",title));
	}

	private void renderGrid() {
		// TODO Auto-generated method stub
		
		if(this.picPath==null){
			throw new RuntimeException("传入的图片路径[list]不能为空");
		}
		
		IDataProvider<String> paths=new ListDataProvider<>(this.picPath);
		
		GridView<String> gridView=new GridView<String>("rows",paths){

			@Override
			protected void populateEmptyItem(Item<String> arg0) {
				// TODO Auto-generated method stub
				arg0.add(new Image("wk_img",new PackageResourceReference(this.getClass(),"empty.png")));
			}

			@Override
			protected void populateItem(Item<String> arg0) {
				// TODO Auto-generated method stub
				arg0.add(new Image("wk_img",new PackageResourceReference(this.getClass(),"name.jpg")));
			}
			
		};
		add(gridView);
		
		gridView.setColumns(3);
		gridView.setRows(3);
	}

}
